package com.kc.gb.device.events;

import com.kc.gb.device.common.dto.RefreshUIEvent;
import com.kc.gb.base.dto.DeviceType;
import com.kc.gb.device.common.utils.SpringHelper;
import com.kc.gb.device.plugins.ptl.events.support.PtlCommandEvent;
import com.kc.gb.device.plugins.strip.listener.support.StripCommandEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class HardwareEventListener {

    @Async
    @EventListener(value = PtlCommandEvent.class)
    public void listenPtlCommandEvent(PtlCommandEvent command){
        // 灯光信号变更后需要通知UI刷新
        log.info("Publish Refresh UI event| PTL Command:{}", command);
        SpringHelper.getApplicationContext().publishEvent(new RefreshUIEvent(DeviceType.PTL));

    }

    @Async
    @EventListener(value = StripCommandEvent.class)
    public void listenStripCommandEvent(StripCommandEvent command){
        // 灯光信号变更后需要通知UI刷新
        log.info("Publish Refresh UI event| Strip Command:{}", command);
        SpringHelper.getApplicationContext().publishEvent(new RefreshUIEvent(DeviceType.STRIP));
    }
}
